package de.earthquake;

import java.util.List;

import model.EarthquakeEntry;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class EarthquakeArrayAdapter extends ArrayAdapter<EarthquakeEntry> {

	private Context context;
	private List<EarthquakeEntry> earthquakes;

	public static class ViewHolder {
		public TextView name;
	}

	
	public EarthquakeArrayAdapter(Context context, int textViewResourceId, List<EarthquakeEntry> objects) {
		super(context, textViewResourceId, objects);
		this.context = context;
		this.earthquakes = objects;
		
	}
	
	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		View row = convertView;
		ViewHolder holder = new ViewHolder();

		if (row == null) {
			LayoutInflater inflater = ((Activity) context).getLayoutInflater();
			row = inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
			holder.name = (TextView) row.findViewById(android.R.id.text1);
			row.setTag(holder);
		} else {
			holder = (ViewHolder) row.getTag();
		}
		
		holder.name.setText(earthquakes.get(position).getTitle());
		
		return row;
	}
}
